﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Forest.Lion.Data;
using Forest.Lion.Model;
using Forest.Lion.Domain.Contracts;

namespace Forest.Lion.Domain.Handlers {
    public class DepartmentHandler {
        private readonly IDepartmentRepository _departmentRepository;

        public DepartmentHandler(IDepartmentRepository departmentRepository) {
            _departmentRepository = departmentRepository;
        }

        public void Create(IDepartmentFormModel formModel,Guid companyId) {
            var entity = new Department {
                Id =formModel.Id,
                DepartmentName = formModel.DepartmentName,
                Tel = formModel.Tel,
                Email = formModel.Email,
                Fax = formModel.Fax,
                Contact = formModel.Contact,
                Mobile = formModel.Mobile,
                DateCreated = DateTime.Now,
                LastUpdated = DateTime.Now,
                Deleted = false,
                CompanyId = companyId,
                CreatedBy = companyId,
                ModifiedBy = companyId
            };

            _departmentRepository.Create(entity);
        }

        public Department GetDepartment(Guid departmentId) {
            return _departmentRepository.GetDepartment(departmentId);
        }

        public IEnumerable<Department> GetDeparmentsForCompany(Guid companyId) {
            return _departmentRepository.GetDepartmentsForCompany(companyId);
        }

        public void Update(IDepartmentFormModel formModel, Guid companyId) {
            var entity = new Department {
                Id = formModel.Id,
                DepartmentName = formModel.DepartmentName,
                Tel = formModel.Tel,
                Email = formModel.Email,
                Fax = formModel.Fax,
                Contact = formModel.Contact,
                Mobile = formModel.Mobile,
                DateCreated = DateTime.Now,
                LastUpdated = DateTime.Now,
                Deleted = false,
                CompanyId = companyId,
                CreatedBy = companyId,
                ModifiedBy = companyId
            };

            _departmentRepository.Update(entity);
        }
    }
}
